import axios from "axios";
import {ElMessage} from "element-plus"
// console.log(process.env);
axios.defaults.baseURL="/api"
// axios.defaults.baseURL=process.env.VUE_APP_URL

axios.interceptors.request.use(function (config) {//请求之前的拦截****************

    if (config.url != "/adminUser/login") {
        config.headers['Token'] =localStorage.getItem("token");//添加token是一把钥匙
    }
    return config;
}, function (error) {
    return Promise.reject(error);
});

axios.interceptors.response.use(function (response) {// 响应之前拦截*************
   

    if(response.data.resultCode!=200){
        ElMessage({
            // showClose: true,
            message: response.data.message,
            type: 'error',
          })
    }else{
        return response.data.data;//过滤出所有接口的 data数据
    }
   
   
}, function (error) {
    return Promise.reject(error);
});
export default axios;